import Koa from 'koa';
import env from './config/env';
import {ApolloServer, gql} from 'apollo-server-koa';
import typeDefs from './graphql/type';
import resolvers from './graphql/resolvers';
import Auth from './lib/Auth';

const server = new ApolloServer({
    typeDefs,
    resolvers,
    context: async (context) => ({
        session: await Auth.handler(context)
    })
});
const app = new Koa();
server.applyMiddleware({app});
const PORT = env('APP_SERVER_PORT', 8090);

app.listen(PORT, () => {
    console.log(`🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`);
});
